package com.polaris.live.viewmodel

import androidx.lifecycle.MutableLiveData
import com.blankj.utilcode.util.StringUtils
import com.polaris.live.common.mvvm.viewmodel.BaseViewModel
import com.polaris.live.common.network.request
import com.polaris.live.common.network.requestLoading
import com.polaris.live.common.network.state.ResultState
import com.polaris.live.common.util.ToastGravity
import com.polaris.live.im.sfs.bean.live.ext.UserBasicVo
import com.polaris.live.net.liveService
import com.polaris.live.resp.base.ListResp
import com.polaris.live.translation.R
import com.polaris.live.widget.refresh.OnListListener

/**
 * WeekSettingViewModel
 *
 * @author Created by 天晴 on 2024/5/13/002 15:55
 */
class WeekSettingViewModel : BaseViewModel(), OnListListener {

    val weekLiveData = MutableLiveData<ResultState<ListResp<UserBasicVo>>>()

    val pageSize = 20  // 每页记录数

    private fun getWeekUser(pageNumber: Int, pageSize: Int = this.pageSize) {
        request({ liveService.rejectList(pageNumber, pageSize) }, weekLiveData)
    }

    //移出通话拒绝清单
    val positionLiveData = MutableLiveData<Int>()
    fun rmRejectList(userId: Long, position: Int) {
        requestLoading({ liveService.rmRejectList(userId) }, {
            positionLiveData.value = position
            ToastGravity.showGravity(StringUtils.getString(R.string.un_week_call_block))
        }, {
            ToastGravity.showGravity(it.errorMsg)
        })
    }

    override fun onRefresh() {
        getWeekUser(pageNumber = 0)
    }

    override fun onLoadMore(pageIndex: Int) {
        getWeekUser(pageNumber = pageIndex)
    }

}